<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>

<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-adverinfo-add" enctype="multipart/form-data" method="POST">
			<div class="form-group">	
				<label class="col-sm-3 control-label">广告标题：</label>
				<div class="col-sm-8">
					<input id="biaoTi" name="biaoTi" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">广告链接：</label>
				<div class="col-sm-8">
					<input id="lianJie" name="lianJie" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">显示顺序：</label>
				<div class="col-sm-8">
					<input id="shunXu" name="shunXu" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">广告状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="true" class="onoffswitch-checkbox" id="status" name="status">
						<label class="onoffswitch-label" for="status">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>

				</div>
			</div>
			<!--<div class="form-group">
				<label class="col-sm-3 control-label">广告图片上传：</label>
				<div class="col-sm-8">
					<input type="file" name="files" onchange="addFile(this)" >
				</div>
			</div>-->
			<div class="form-group">
				<style type="text/css">
				</style>
				<label class="col-sm-3 control-label">广告图片上传：</label>
				<div class="col-sm-8">
					<div class="file-loading" style="width: 80%">
						<input id="files" class="file" name="file" type="file" data-show-upload="false" language="zh"
							   data-show-Cancel="false" data-theme="fas">
					</div>
				</div>
			</div>
		</form>
	</div>
	<script type="text/javascript">
		var content = "";
		var types = "image";//默认图片
		var fileTypes = "image";//默认类型

		//初始化插件基础信息
		$("#files").fileinput({
			language: 'zh',
			maxFileCount: 1,
			dropZoneEnabled: false,
			initialPreview: [
				'[[${avatar}]]'
			],
			initialPreviewConfig: [ //配置预览中的一些参数
				{  filetype: fileTypes, size: 329892, width: "120px", key: 1},
			],
			showCaption: false,
			allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif"],
			initialPreviewAsData: true,
			overwriteInitial: true,
			layoutTemplates: {
				actionDelete: ''//预览页面的删除按钮设置为不显示
			}
		})
	</script>
    <div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
	<script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>

	<script type="text/javascript">
	/*	function addFile(obj) {
			var o = $(obj);
			var len = o.parent().find('input').length;
			if(o[0].value == ''){
				if(len > 1){
					o.remove();
				}
			}else{
				o.parent().append('<input type="file" name="files" onchange="addFile(this)">')
			}
		}
		var prefix = ctx + "system/adverinfo"
		$("#form-adverinfo-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});

		function submitHandler() {
			if ($.validate.form()) {
				var ids = '';
				$(':file').each(function(i){
					if($(this).val() != ''){
						$(this).attr('id', 'img'+i)
						ids += ',img'+i;
					}
				});
				$.operate.save2(prefix + "/add", $('#form-adverinfo-add').serialize(), ids.substring(1));
			}
		}
		$.fn.imgs = function(e) {
			var fileObj = $('<input type="file">');
			var name = "";
			if (this.attr('name')) {
				name = ' name="' + this.attr('name') + '"';
			}
			var hiddenObj = $('<input type="hidden"' + name + '">');
			this.parent().append(hiddenObj);
			var imgObj = $(this.attr('img'));
			fileObj.trigger('click');
			fileObj.change(function() {
				var reader = new FileReader();
				reader.onload = function(e) {
					imgObj.attr('src', e.target.result);
					hiddenObj.val(e.target.result)
				}
				reader.readAsDataURL($(this).context.files[0]);
			});
		}
*/




	$(function () {
		show();
		$('.summernote').summernote({
			height: '220px',
			lang: 'zh-CN'
		});
	})
	function show() {
		//图片

			$("#files").parents(".form-group").show();

	}

	function submitHandler() {
		if ($.validate.form()) {
			var form = new FormData();

			var file = document.getElementById("files").files[0];
			form.append("file", file);
			$.ajax({
				url: prefix + "/add",
				data: form,
				type: "POST",
				dataType: "json",
				processData: false,
				contentType: false,
				success: function (result) {
					$.operate.saveSuccess(result);
				}
			});
		}
	}
	</script>
</body>
</html>
